from __future__ import unicode_literals

from django.db import models
from django.core.urlresolvers import reverse


class Tag(models.Model):
    tag_name = models.CharField(max_length=64)

    def __unicode__(self):
        return self.tag_name


class Article(models.Model):
    title = models.CharField(max_length=100)   #博客正文
    category = models.CharField(max_length=50, blank=True)#博客标签，空字符串
    tag = models.ManyToManyField(Tag, blank=True)
    date_time = models.DateTimeField(auto_now_add=True)#博客时间，用于存储时间，
                                                       # 为true表示自动设置增加时间
    content = models.TextField(blank=True, null=True)
    #博客文章正文


    def get_absolute_url(self):
        path = reverse('detail', kwargs={'id': self.id})
        return "http://127.0.0.1:8000%s" % path

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ['-date_time']
